package com.imooc.rabbitmq.exchange.topic;

import com.imooc.rabbitmq.utils.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class TopicProducer {

    private static final String exchangeName = "test_topic_exchange";
    private static final String routingKey1 = "user.save";
    private static final String routingKey2 = "user.update";
    private static final String routingKey3 = "user.delete.abc";

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtils.getConnection();

        //2. 通过Connection 创建一个channel
        Channel channel = connection.createChannel();

        String msg = "Hello RabbitMQ! Topic Exchange Message ...";
        channel.basicPublish(exchangeName,routingKey1,null,msg.getBytes());
        channel.basicPublish(exchangeName,routingKey2,null,msg.getBytes());
        channel.basicPublish(exchangeName,routingKey3,null,msg.getBytes());

        channel.close();
        connection.close();
    }
}
